package javaClassExercise.multiThreading;

/**
 * Java多线程创建方式：
 * 1. 通过集成Thread类
 * 2. 通过实现Runnable接口
 * 3. 通过Callable和Future创建多线程
 * Created by lomo.
 */

/**
 * 第一种：通过继承Thread类实现
 */
public class MultiThreads extends Thread {

    public static void main(String... args) {
        Main m = new Main("Lomo1");
        m.start();
//        m.start();  // 错误写法
        m.run();
        Main m2 = new Main("Lomo2");

        m2.start();
    }



}

class Main extends Thread{
    private static int num = 5;
    private String name;

    Main(String s) {
        this.name = s;
        System.out.println("--子类Main--" + s);
    }

    //    多线程的处理逻辑 重写于此
    @Override
    public void run() {
        for (int i = 0; i < this.num; i ++) {
            System.out.println("线程" + this.name  + ": " + Thread.currentThread().getName() + " num = " + i);
        }
    }
}